package com.athuahua.spzx.controller;

import com.athuahua.spzx.entity.UserAddress;
import com.athuahua.spzx.service.UserAddressService;
import com.athuahua.spzx.utils.Result;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: huahua
 * @Date: 2024/8/17 0017
 * @Time: 23:03
 * @Description:
 */
@Tag(name = "用户地址管理模块接口")
@RestController
@RequestMapping("api/user/userAddress")
@Slf4j
public class UserAddressController {

    @Resource
    private UserAddressService userAddressService;

    /**
     * 获取用户地址列表
     * @return
     */
    @GetMapping("/auth/findUserAddressList")
    public Result findUserAddressList() {
        List<UserAddress> list = userAddressService.findUserAddressList();

        return Result.success(list);
    }

    /**
     * 通过id获取地址
     * @param id
     * @return
     */
    @GetMapping("/getUserAddress/{id}")
    public UserAddress getUserAddress(@PathVariable("id") Long id) {
        return userAddressService.getById(id);
    }




    @DeleteMapping("auth/removeById/{id}")
    public Result removeById(@PathVariable("id") Integer id) {
        userAddressService.removeById(id);

        return Result.success();
    }

    /**
     * 请求 URL:
     * http://localhost:8500/api/user/userAddress/auth/updateById
     * 请求方法:
     * PUT
     * 更新用户地址
     */

    @PutMapping("auth/updateById")
    public Result updateById(@RequestBody UserAddress userAddress) {
        userAddressService.iUpdateById(userAddress);
        return Result.success();
    }

    /**
     * 请求 URL:
     * http://localhost:8500/api/user/userAddress/auth/save
     * 请求方法:
     * POST
     * 保存用户地址
     */
    @PostMapping("auth/save")
    public Result save(@RequestBody UserAddress userAddress) {
        userAddressService.iSave(userAddress);
        return Result.success();
    }
}
